<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends BaseAction{


    //排名
    public function ranking(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        ///dump("1121212");

        $this->rankList = D("User")->order("totalVote desc")->top50();
        //dump($this->rankList);
        $this->display();
    }


    public function changepwd(){
        //dump("显示页");
        $vo = D("User")->where("id=".$this->mid)->find();
        //dump($vo);
        $this->vo = $vo;
        $this->display();
    }
    public function cpwding(){
        $Dao = D("User");
        $vo = 	$Dao->create();
        $Dao->save();
        $this->success("操作成功");

    }
    public function index(){

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->match = D ('Article')->where("nid=5")->order('id desc')->top12();
        $this->synopsis = D('Page')->where("nid=4")->find();
        $this->announcement = D('Affiche')->order("cTime desc")->find();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        $this->plist = D('Picture')->where("nid=8")->find();
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();
        $this->piclist =D("UserpicView")->order("cTime desc")->top9();

        $this->display();
        //dump($this->synopsis);
    }



    public function product(){
        $nid = $_GET['nid'];
        $map	=	new HashMap();
        if($nid) $map->put('nid',$nid);

        //import("ORG.Util.Page");

        include './Public/Page.class.php';
        $count = D('Product')->count($map);
        $p = new Page($count,4);

        $this->plist = D('Product')->findAll($map,"*","cTime desc",$p->firstRow.",".$p->listRows);
        $this->title = getSysnavName($nid);
        $this->page = $p->show();

        //dump($this->title);
        //dump($this->plist);
        $this->display();
    }



    public function page(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        //dump($this->link1);
        $id = $_GET['id'];
        $nid = $_GET['nid'];
        $map	=	new HashMap();
        if($id) $map->put('id',$id);
        if($nid) $map->put('nid',$nid);
        //dump($nid);
        $this->vo = D('Page')->where($map)->order('id desc')->find();
        //dump($this->vo);
        $this->title = $this->vo['title'];
        $this->description = "沈阳网站建设沈阳网站建设为你提供880元拥有一套你想要的设计网站，沈阳网站建设沈阳钦和网站建设公司主要以网站制作,网站建设为主要业务,为企业和公司提供网站搜索引擎优化服务，在沈阳网站建设行里，沈阳网站建设钦和网络已成立，服务大小企业500多家，多年的经验让我们对网站制作有了与众不同的风格与定位,我们服务于各行各业，想于每个企业建立长期的合作关系。";
        $this->keywords = $this->vo['title'] ;

        $this->display();
    }


    public function article(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        //dump($this->link1);
        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $fid = $_GET['fid'];
        $nid = $_GET['nid'];
        $map	=	new HashMap();
        if($fid) $map->put('categoryID',$fid);
        if($nid) $map->put('nid',$nid);
        //$map ->put("moduleID",2);
        //import("ORG.Util.Page");
        include './Public/Page.class.php';
        $listRows = 10;
        $count = D('Article')->count($map);
        $p = new Page($count,$listRows);
        $this->alist = D('Article')->findAll($map,"*","id desc",$p->firstRow.",".$p->listRows);
        $this->page = $p->show();

        $this->title = getSysnavName($nid);;

        //dump($this->alist);
        //$this->left();
        $this->display();
    }

    public function articlec(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $id = $_GET['id'];
        if(!$id) $this->error('id参数丢失！');
        $this->vo = D('Article')->order('id desc')->find($id);

        $this->title = $this->vo['title'];
        //dump($this->vo);
        $this->display();
    }

    public function book(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        $this->title  =  '留言板';

        $map = "1=1 ";
        $map .= " and reply<>''";
        $count  =D('Book')->count($map);
        //include './Public/Page.class.php';
        import("ORG.Util.Page");
        $listRows = 5;
        $count = D('Book')->count($map);
        $p = new Page($count,$listRows);
        $this->booklist = D('Book')->findAll($map,"*","cTime desc",$p->firstRow.",".$p->listRows);

        $this->page = $p->show();
        $this->display();

    }


    public function booking(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();

        if(md5($_POST['verify']) != $_SESSION['verify']){
            $this->error("验证码输入错误!");
        }

        $Dao = D('Book');

        $vo = $Dao->create();
        //dump($vo);
        if(false === $vo) {
            $this->error($Dao->getError());
        }
        $rs = $Dao->add();
        if($rs){
            //发邮件
            include './Public/SendEmail.php';
            //$email = C('SMTP_SENDER_EMAIL');//发送邮件
            $content = "您的网站有新的留言，请注意查收，http://www.qhcms.com";//内容
            $isSend = SendEmail("zq535228@sina.com", '新的留言__'.toDate(time()),$content );
            if(!$isSend){
                $this->error('邮件发送失败!');
            }

            $this->assign("jumpUrl",__APP__."/index/book/nid/".$_POST['nid']);
            $this->success("添加数据成功!");
        }else{
            $this->error("添加数据失败");
        }

    }



    public function affiche(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        $this->announcement = D('Affiche')->order("cTime desc")->find();
        $id = $_GET['id'];
        if(!$id) $this->error('id参数丢失！');
        $this->vo = D('Affiche')->find($id);
        //dump($this->vo);
        //$this->left();
        $this->display();
    }

    public function plist(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        //$map ->put("moduleID",2);
        import("ORG.Util.Page");
        //include './Public/Page.class.php';
        $listRows = 16;


        $count = D('User')->count("id=".$_GET['uid']);
        $p = new Page($count,$listRows);
        $this->piclist = D('UserpicView')->findAll("User.id=".$_GET['uid'],"*","id asc",$p->firstRow.",".$p->listRows);
        //dump(D('UserpicView')->getLastSql());exit;
        $this->page = $p->show();

        $this->display();


    }

    public function picture(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();

        import("ORG.Util.Page");
        $listRows = 16;
        $map = "1=1 ";
        $kname = $_GET['kname'];
        $bname = $_GET['bname'];
        if($kname) $map .=" and kname like '%".$kname."%'";
        if($bname) $map .=" and bname like '%".$bname."%'";

        $count = D('User')->count($map);
        $p = new Page($count,$listRows);
        $this->piclist = D('User')->findAll($map,"*","id desc",$p->firstRow.",".$p->listRows);
        //dump(D('User')->getLastSql());
        $this->page = $p->show();

        $this->display();
    }
    public function picturec(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();

        $id = $_GET['id'];
        if(!$id) $this->error('id参数丢失！');
        $this->vo = D('UserpicView')->find("Userpic.id=$id");

        //$this->left();
        $this->title = $this->vo['picName'];

        //评论的循环显示
        $this->userCommList = D("Usercomment")->where("pid=".$id)->order("cTime asc")->findAll();

        //下一个
        $Dao=  D('Userpic');
        $nextID = $Dao->field('id')->where("id>$id and userID=".$this->vo['userID'])->order('id asc')->limit('1')->find();
        $this->assign('nextID',$nextID);

        //上一个
        $preID = $Dao->field('id')->where("id<$id and userID=".$this->vo['userID'])->order('id desc')->limit('1')->find();
        $this->assign('preID',$preID);

        $this->display();
    }

    public function picvoting(){
        $nTime = time();
        $eTime = strtotime("2009-5-26");
        $tmpTime = $nTime-$eTime;
        if($tmpTime>0) $this->success("热烈庆祝本次比赛结束，请勿再投票啦。");


        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();
        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();
        $id = $_GET['id'];

        //判断地址是否为金宝贝
        $address = $_SERVER['HTTP_REFERER'];
        $islocation = strpos($address, "hidr.cn");
        if(!$islocation){
            $this->error("禁止跨站提交");
        }

        //判断是否重复投票
        $cip = $_SERVER['REMOTE_ADDR'];
        $isVoted = S("voted".$id.$cip);
        if($isVoted){
            $this->error("请勿重复投票哦！您的IP:$cip,请您在1个小时内，只允许对编号：$id 的图片投票一次！");
        }else{
            S("voted".$id.$cip, "1",3600);//十分钟
        }




        D('Userpic')->setInc("picVoteNum","id=$id");
        $uid = D("Userpic")->getField("userID","id=$id");
        D("UserpicView")->updateVote($uid);
        $this->success("投票成功");
    }



    public function upload0(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();

        $this->piclist = D("Userpic")->where("userID=$this->mid")->order("cTime desc")->findAll();
        $this->display();
    }

    public function uploading(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->top10();

        $mypcount = D("Userpic")->count("userID=".$this->mid);
        if($mypcount>8) $this->error("您不能在上传了，您已经上传了9张照片了。");

        if(!empty($_FILES['file1']['name'])){
            $tmp = $this->upload("./Public/file/");
            $tmp = $tmp[0]["savename"];
            $result =  $this->Thumb("./Public/file/$tmp", "400", "550");
            $result2 = $this->Thumb("$result", "101", "89");
            unlink("./Public/file/$tmp");
        }else{
            $this->error("您还没有选择照片呢！");
        }
        $Dao = D("Userpic");
        $Dao->create();
        $Dao->userID = $this->mid;
        $Dao->picUrl = $result;
        $Dao->picUrl2 = $result2;
        $Dao->add();
        //dump($Dao->add);
        $this->success("上传成功！");
    }

    public function delpic(){
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();

        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->order("orderNum")->top10();

        $id = $_GET['id'];
        $uid = $this->mid;
        $Dao= D("Userpic");

        $file  = $Dao->getField("picUrl","id=$id and userID =$uid");
        if($file) unlink($file);

        $file2  = $Dao->getField("picUrl2","id=$id and userID =$uid");
        if($file2) unlink($file2);

        $Dao->delete("id=$id and userID =$uid");
        //dump($Dao->getLastSql());
        $this->success("删除照片成功！");
    }

    public function piccomming(){
        //$this->validateLoginFriend();
        $Dao=  D("Usercomment");
        $content = trim($_POST['content']);
        if(!$content) $this->error("请输入内容！");

        $vo =  $Dao->create();
        $Dao->add();
        $this->success("感谢您的留言！");
    }

    function setMain(){
        $pid = $_GET['pid'];
        D("Userpic")->setField("isMain","1","id=$pid");


        $this->success("设置成功！");
    }

    function unsetMain(){
        $pid = $_GET['pid'];
        D("Userpic")->setField("isMain","0","id=$pid");
        $this->success("取消成功！");
    }



}
?>